package 复制带随机指针的链表138;

import java.util.HashMap;

/**
 * @author 谢阳
 * @version 1.8.0_131
 */

class Solution {
    public static void main(String[] args) {
    }

    public static Node copyRandomList(Node head) {
        HashMap<Node, Node> hashMap = new HashMap<>();
        Node cur = head;

        while (cur != null) {
            hashMap.put(cur, new Node(cur.val));
            cur = cur.next;
        }
        cur = head;
        while (cur != null) {
            hashMap.get(cur).random = hashMap.get(cur.random);
            hashMap.get(cur).next = hashMap.get(cur.next);
            cur = cur.next;
        }

        return hashMap.get(head);



    }
}

class Node {
    int val;
    Node next;
    Node random;

    public Node(int val) {
        this.val = val;
        this.next = null;
        this.random = null;
    }
}